package com.hjm.project.agentInfo.agentRecord.controller;

import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.framework.web.page.TableDataInfo;
import com.hjm.project.merchantInfo.merRecord.domain.MerRecord;
import com.hjm.project.merchantInfo.merRecord.service.IMerRecordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商户换机,商户迁移Controller
 *
 * @author maker-platform
 * @date 2021-04-01
 */
@Controller
@RequestMapping("/agentRecord/agentRecord")
public class AgentRecordController extends BaseController
{
    private String prefix = "agentInfo/agentRecord";

    @Resource
    private IMerRecordService merRecordService;

    @RequiresPermissions("agentRecord:agentRecord:view")
    @GetMapping()
    public String agentRecord()
    {
        return prefix + "/agentRecord";
    }

    @RequiresPermissions("agentRecord:agentRecord:view")
    @GetMapping("/agentRecordAgent")
    public String merRecordAgent()
    {
        return prefix + "/agentRecordAgent";
    }


    @RequiresPermissions("agentRecord:agentRecord:view")
    @GetMapping("/agentRecordUpdate")
    public String agentRecordUpdate()
    {
        return prefix + "/agentRecordUpdate";
    }

    /**
     * 查询代理迁移列表
     */
    @RequiresPermissions("agentRecord:agentRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MerRecord merRecord)
    {
        startPage();
        List<MerRecord> list = merRecordService.selectMerRecordList(merRecord);
        return getDataTable(list);
    }

    /**
     * 导出代理迁移列表
     */
    @RequiresPermissions("agentRecord:agentRecord:export")
    @Log(title = "代理迁移", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MerRecord merRecord)
    {
        List<MerRecord> list = merRecordService.selectMerRecordList(merRecord);
        ExcelUtil<MerRecord> util = new ExcelUtil<MerRecord>(MerRecord.class);
        return util.exportExcel(list, "merRecord");
    }

    /**
     * 新增代理迁移
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存代理迁移
     */
    @RequiresPermissions("agentRecord:agentRecord:add")
    @Log(title = "代理迁移", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MerRecord merRecord)
    {
        return toAjax(merRecordService.insertMerRecord(merRecord));
    }

    /**
     * 修改代理迁移
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        MerRecord merRecord = merRecordService.selectMerRecordById(id);
        mmap.put("merRecord", merRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存代理迁移
     */
    @RequiresPermissions("agentRecord:agentRecord:edit")
    @Log(title = "代理迁移", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MerRecord merRecord)
    {
        return toAjax(merRecordService.updateMerRecord(merRecord));
    }

    /**
     * 删除代理迁移
     */
    @RequiresPermissions("agentRecord:agentRecord:remove")
    @Log(title = "代理迁移", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(merRecordService.deleteMerRecordByIds(ids));
    }
}
